<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/view/include/css-include.jsp"%>
<%@ include file="/view/include/jsp-include.jsp"%>
<%@ include file="/view/include/jquery-include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ACTUAL STOCK STATUS</title>

<script type="text/javascript">
	$().ready(function() { 
		<%-- 달력 --%>
        calendar.makeCalender("expiredDate");
        //calendar.makeCalender("endDate");
        
        var now = new Date();
	    var year= now.getFullYear();
	    var mon = (now.getMonth()+1)>9 ? ''+(now.getMonth()+1) : '0'+(now.getMonth()+1);
	    var day = now.getDate()>9 ? ''+now.getDate() : '0'+now.getDate();
	        
	    $('#expiredDate').val(year+"-"+mon+"-"+day);
    
        
		//view(1);   
		$("#onWrite").bind("click",function(){
            location="/customerWrite.html";            
        });
	    /* 조회버튼 */
	    $("#btnSearch").bind("click",function(){       
	    	view(1);
	    });
	    
	});

	function view(page){
		$.post(
                '/getActualStockStatusView.json', {                      
                paging : page,//odrNo,
                listScale : "15",
               // startDate : $("#startDate").val(),
                expiredDate : $("#expiredDate").val(),
                custCodeUser : $("#custCodeUser").val(),
                roleId : $("#roleId").val(),
                goodsCode : $("#sGoodsCode").val(),
                sMessrs :  $("#sMessrs").val(),
                custCode : $("#sCustCode").val(),
                lotNo : $("#batchNo").val()
               },
            function(data) {
                //$("#actualStockStatusDetail").remove();
                //reSetValidete(); //벨류데이션 초기화
                searchDataMaping(data);    //DATA맵핑 
            });
	}
	
	/* searchData 맵핑 */
    function searchDataMaping(data){
    	   
    	var contents = "";
    	var cHeader = "<tr>"
    		+"<th width='35%'>Goods</th>"
    		+"<th width='25%'>Batch</th>"
    		+"<th width='25%'>Short Shelf-Life Date</th>"
    		+"<th width='15%'>Qty</th>"
    		+"</tr>";
        if(data.resultList.length == 0){
            contents = "<tr><td colspan='4' height='50' bgcolor='#FFFFFF' align='center'><B>No Data</B></td></tr>";
            $("#actualStockStatusDetail").html(cHeader+contents);
                
        }else{ 
	        $.each(data.resultList, function(index){  // List로 받아온값 (여러건)  
	           contents += "<tr style='cursor:pointer' onclick='rowSelect(this)'><td align='center' class='boSub'>"+this.goodsName+"</td>"
	        	   +"<td align='center'>"+this.batchNo+"</td>"
	        	   +"<td align='center'>"+this.expiredDate+"</td>"
	        	   +"<td align='center'>"+this.qty+"</td>"
	               +"</tr>";
	            
	        });
        }
        
        var totalPage = Math.ceil(parseInt(data.actualStockStatusCount)/parseInt(15));        
        $("#spanCount").empty().html("Total : "+data.actualStockStatusCount);
        $("#pageCount").empty().html("Page : "+$("#pageNum").val()+" / "+totalPage);                    
        $("#page").empty().html(data.pageSplit);
        
        $("#actualStockStatusDetail").html(cHeader+contents);  // 조회 값 뿌리기
        $("#actualStockStatusDetail tr:eq(1)").click(); 
        
    }

    function ajaxPageSplit(num) {
    	$("#pageNum").val(num);
        view(num);
    }
    
    function rowSelect(obj){
        $("#actualStockStatusDetail tr").css("backgroundColor","#FFFFFF");
        obj.style.backgroundColor="#e0eeee";  
    }

    /************************************************************************/
    /*                      고객 팝업 버튼 , 리턴값처리                     */
    /************************************************************************/
    var popType ="";
    /* 고객 팝업 버튼 */
    function customerPopCall(obj, type){
        popType = type; 
        var custCodeTmp = "";
        if($("#roleId").val() == "3"){
            custCodeTmp = $("#custCodeUser").val();
        }
        if(type == 'E'){
            window.open('/customerPop.html?customer=3&messrsCode='+custCodeTmp, 'customerPop', 'width=415, height=500, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
        }else{
            window.open('/customerPop.html?customer=2', 'customerPop', 'width=415, height=500, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
        }
    }
    
    /* 고객정보 맵핑 */
    function customerPopValue(custCode , custName , addr1 , addr2, tel, fax){  
         switch(popType){
         case "E":
               $("#sCustCode").val(custCode);
               $("#sCustName").val(custName); 
               break;
         case "M":
             $("#sMessrs").val(custCode);
             $("#sMessrsName").val(custName); 
             break;
         }
           popType = "";
    };
    
    /************************************************************************/
    /*                      상품 팝업 버튼 , 리턴값처리                     */
    /************************************************************************/
    /* 상품 팝업 버튼 */
    function onProductPopup(obj){
    	var custCodeTmp = "";
        if($("#roleId").val() == "3"){
            custCodeTmp = $("#custCodeUser").val();
        }
        window.open('/productPop.html?custCode='+custCodeTmp, 'changeProductPop', 'width=615, height=450, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
    }

    function productPopValue(goodsCode, goodsName, unit, boxQty, hsCode, productCode, custCode, custName){

        $("#sGoodsCode").val(goodsCode);
        $("#sGoodsName").val(goodsName);   
    }
</script>
</head>
<body>
<div class="wrap">
	<div class="pagetitle">
    	<h1>ACTUAL STOCK STATUS</h1>
	</div>
    <div>
    	<table class="TableST">
            <!-- >tr>
            	<th width="15%">Date</th>
                <td width="35%">
                	<input type="text" class="inST30" id="startDate" name="startDate" maxlength="10"/> ~
                	<input type="text" class="inST30" id="endDate" name="endDate" maxlength="10"/>
                </td>
                <th width="15%">Goods</th>
                <td width="35%">
                	<input type='text' class='inSTR70' name='sGoodsName' id='sGoodsName'/>
                    <img src='/images/web/bkn_zoom.gif' aligh='right' id='stockOutPop' onclick='onProductPopup(this);'>
                    <input type='hidden' class='inSTR95' name='sGoodsCode' id='sGoodsCode'/>
                </td>
            </tr-->
            <tr>
                <th width="15%">Goods</th>
                <td width="35%">
                    <input type='text' class='inSTR70' name='sGoodsName' id='sGoodsName' readonly/>
                    <img src='/images/web/bkn_zoom.gif' aligh='right' id='stockOutPop' onclick='onProductPopup(this);'>
                    <input type='hidden' class='inSTR95' name='sGoodsCode' id='sGoodsCode'/>                  
                </td>
                <th width="15%">Batch</th>
                <td>
                    <input type="text" class="inST70" name="batchNo" id="batchNo" maxlength="20"/>
                </td>
            </tr>
            <tr>
                <th>End User</th>
                <td>
                    <input type="text" class="inSTR70" id="sCustName" name="sCustName" readonly onFocus="blur();" value="" readonly/>
                    <img alt="Search" hight="16" width="16" onclick="customerPopCall(this, 'E')" src="/images/web/bkn_zoom.gif">
                    <input type="hidden" class="inSTR20" id="sCustCode" name="sCustCode" readonly onFocus="blur();" value=""/>
                </td>
                <th>Messrs</th>
                <td>
                    <input type="text" class="inSTR70" id="sMessrsName" name="sMessrsName" maxlength="20"/>
                    <input type="hidden" id="sMessrs" name="sMessrs" />
                    <img alt="Search" hight="16" width="16" onclick="customerPopCall(this, 'M')" src="/images/web/bkn_zoom.gif">
                </td>
            </tr>
            <tr>
                <th>Short Shelf-Life Date</th>
                <td colspan="3">
                    <input type="text" class="inSTR30" id="expiredDate" name="expiredDate" value="" readonly/>
                </td>
            </tr>
        </table>
        <div class="bo_btnS">
	        <ul class="btnst"><li class="a"><a href="#" id="btnSearch" >SEARCH</a></li></ul>
	    </div>
        <br/><br/><br/><br/>
        <ul>
        	<li class="totaltext"><span id="spanCount">Total : 0</span></li>
            <li class="pagetext"><span id="pageCount">Page : 1&frasl;1</span></li>
            <li class="bolistW">
            	<table class="TableST4" id="actualStockStatusDetail">
            	<tr>
		            <th width='35%'>Goods</th>
		            <th width='25%'>Batch</th>
		            <th width='25%'>Short Shelf-Life Date</th>
		            <th width='15%'>Qty</th>
	            </tr>
                	<!-- tr>
                    	<th width="20%">DATE</th>
                        <th width="20%">GOODS</th>
                        <th width="20%">LOT.NO</th>
                        <th width="20%">QTY</th>
                        <th width="20%">TEMPERATURE</th>
                    </tr>
                    <span id="actualStockStatusDetail">
                        <tr>
                           <td colspan="5"></td>    
                        </tr>
                    </span-->                    
                </table>
            </li>
        </ul>
    </div>
    <div class="page_wrap">
        <div class="page" id="page" >
        </div>
    </div>
    <input type="hidden" name="pageNum" id="pageNum" value="1">
    <input type="hidden" name="custCodeUser" id="custCodeUser" value="${requestScope.custCodeUser}">
    <input type="hidden" name="roleId" id="roleId" value="${requestScope.roleId}">
</div>
</body>
</html>